﻿Imports System
Imports System.Collections
Imports System.ComponentModel

Namespace System.Workflow.ComponentModel.Design
    Friend NotInheritable Class ReadonlyPropertyDescriptor
        Inherits PropertyDescriptor
        ' Methods
        Friend Sub New(ByVal descriptor As PropertyDescriptor)
            MyBase.New(descriptor, Nothing)
            Me.realPropertyDescriptor = descriptor
        End Sub

        Public Overrides Function CanResetValue(ByVal component As Object) As Boolean
            Return False
        End Function

        Public Overrides Function GetValue(ByVal component As Object) As Object
            Return Me.realPropertyDescriptor.GetValue(component)
        End Function

        Public Overrides Sub ResetValue(ByVal component As Object)
            Me.realPropertyDescriptor.ResetValue(component)
        End Sub

        Public Overrides Sub SetValue(ByVal component As Object, ByVal value As Object)
        End Sub

        Public Overrides Function ShouldSerializeValue(ByVal component As Object) As Boolean
            Return Me.realPropertyDescriptor.ShouldSerializeValue(component)
        End Function


        ' Properties
        Public Overrides ReadOnly Property Attributes As AttributeCollection
            Get
                Dim list As New ArrayList
                Dim attribute As Attribute
                For Each attribute In Me.realPropertyDescriptor.Attributes
                    If (Not TypeOf attribute Is EditorAttribute AndAlso Not TypeOf attribute Is ReadOnlyAttribute) Then
                        list.Add(attribute)
                    End If
                Next
                list.Add(New ReadOnlyAttribute(True))
                Return New AttributeCollection(DirectCast(list.ToArray(GetType(Attribute)), Attribute()))
            End Get
        End Property

        Public Overrides ReadOnly Property Category As String
            Get
                Return Me.realPropertyDescriptor.Category
            End Get
        End Property

        Public Overrides ReadOnly Property ComponentType As Type
            Get
                Return Me.realPropertyDescriptor.ComponentType
            End Get
        End Property

        Public Overrides ReadOnly Property Converter As TypeConverter
            Get
                Return Me.realPropertyDescriptor.Converter
            End Get
        End Property

        Public Overrides ReadOnly Property Description As String
            Get
                Return Me.realPropertyDescriptor.Description
            End Get
        End Property

        Public Overrides ReadOnly Property IsReadOnly As Boolean
            Get
                Return True
            End Get
        End Property

        Public Overrides ReadOnly Property PropertyType As Type
            Get
                Return Me.realPropertyDescriptor.PropertyType
            End Get
        End Property


        ' Fields
        Private realPropertyDescriptor As PropertyDescriptor
    End Class
End Namespace

